package net.cgsoft.widget.https.okhttp;

import android.os.Handler;
import android.os.Looper;

import com.google.gson.Gson;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Created by Youga on 2015/8/25.
 */
public class OkHttpUtil{

    private final OkHttpClient mOkHttpClient;
    private final Handler mDelivery;
    private static OkHttpUtil mInstance;
    private final Gson mGson;

    private OkHttpUtil() {
        mOkHttpClient = new OkHttpClient.Builder()
                .connectTimeout(5000, TimeUnit.MILLISECONDS)
                .readTimeout(10000, TimeUnit.MILLISECONDS)
                .writeTimeout(10000, TimeUnit.MILLISECONDS)
                .build();
        mDelivery = new Handler(Looper.getMainLooper());
        mGson = new Gson();
    }

    public static OkHttpUtil getInstance() {
        if (mInstance == null) {
            synchronized (OkHttpUtil.class) {
                if (mInstance == null) mInstance = new OkHttpUtil();
            }
        }
        return mInstance;
    }

    public OkHttpClient getOkHttpClient() {
        return mOkHttpClient;
    }

    public Handler getDelivery() {
        return mDelivery;
    }

    public Gson getGson() {
        return mGson;
    }
}
